package com.faner.sys;

import com.faner.source.SpringSourceCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LogCostInterceptor extends SpringSourceCode implements HandlerInterceptor {
    private static Logger logger = LoggerFactory.getLogger(LogCostInterceptor.class);

    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
        logger.warn("拦截器开始了！-----");
        String ipAddr = SpringSourceCode.getIpAddr(httpServletRequest);
        logger.info("访问IP：{}",ipAddr);
        return false;
    }

    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
        logger.info("后置拦截器，鬼知道干啥的！");
    }

    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
        output("拦截结束！--");
    }
}
